<?php
/**
 * @name CourtController
 * @author winky
 * @desc
 */

class CourtController extends CommonController
{
    public function init()
    {
        parent::init();
        $this->_bizType     = "court";
        $this->_action      = "";
    }

    public function getCourtInfoAction()
    {
        $this->_func = __FUNCTION__;
        $this->chkGroundData();

        $groundID = $this->_postData['ground_id'];
        $courtInfo = D('Court')->getCourtInfo($groundID);
        if(empty($courtInfo)) {
            $this->_errCode = 12;
            $this->_errMsg = '非法的场地ID';
            $this->outputMsg();
        }

        trace(json_encode($courtInfo), 'getCourtInfoAction', 'DEBUG', true);
        $this->_reinfo = $courtInfo;
        $this->outputMsg();
    }

    private function chkGroundData()
    {
        $this->chkPostData();
        $this->chkRequestParams();

        $token = $this->_postData['access_token'];
        $groundID = $this->_postData['ground_id'];
        if (!D('Court')->isValidToken($token, $this->_clientVersion)) {
            $this->_errCode = 11;
            $this->_errMsg = "非法的令牌";
            $this->outputMsg();
        }

        return D('Court')->createGroundToken($token, $groundID, $this->_clientVersion);
    }
}

